package com.superman.supermarket.client.activity;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.event.ToastEvent;
import com.superman.mvpframe.client.mvp.IPageView;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.Registry;
import com.superman.supermarket.client.mvp.ShopAbstractActivity;
import com.superman.supermarket.client.view.addredit.AddrEditView;
import com.superman.supermarket.client.view.addredit.AddrEditView.AddrEditViewPresenter;

/**
 * 地址编辑
 * 
 * @author superman
 * @version 2018年8月2日下午5:02:24
 */
public class AddrEditActivity extends ShopAbstractActivity implements AddrEditViewPresenter {

	@Inject
	AddrEditView addrEditView;
	private String addrId;

	@Override
	public IPageView getView() {
		return addrEditView;
	}

	@Override
	public IPageViewPresenter getViewPresenter() {
		return this;
	}

	@Override
	public void onActivity(EventBus eventBus) {
		addrEditView.setHeaderText("编辑收货地址");
	}

	@Override
	public void popToRefresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void popToRefresh(Object contextData) {
	}

	@Override
	public void pushToRefresh() {
		if (Registry.get("addrinfo") != null) {
			Map<String, Object> map = Registry.get("addrinfo");
			this.addrId = String.valueOf(map.get("ADDR_ID"));
			addrEditView.setDefaultAddrInfo(String.valueOf(map.get("RECEIVER")), String.valueOf(map.get("PHONE_NO")),
					String.valueOf(map.get("AREA_CODE")), String.valueOf(map.get("RECEIVE_AREA")), String.valueOf(map.get("RECEIVE_ADDR")));
		}

	}

	@Override
	public void save(String receivername, String telno, String areacode, String area, String address) {

		final Map<String, Object> map = new HashMap<String, Object>();
		map.put("ADDR_ID", this.addrId);
		map.put("RECEIVER", receivername);
		map.put("PHONE_NO", telno);
		map.put("AREA_CODE", areacode);
		map.put("AREA", area);
		map.put("DETAIL_ADDR", address);
		postman.post("address/update", map, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				eventBus.fireEvent(new ToastEvent("地址更新成功"));

				placeController.back(map);
			}
		});

	}

}
